package com.bit.springblogdemo.common.util;

import com.bit.springblogdemo.pojo.dataobject.BlogInfo;
import com.bit.springblogdemo.pojo.dataobject.UserInfo;
import com.bit.springblogdemo.pojo.request.UpdateBlogRequest;
import com.bit.springblogdemo.pojo.response.BlogInfoResponse;
import com.bit.springblogdemo.pojo.response.UserInfoResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

@Component
public class BeanTransUtils {
    public static BlogInfoResponse trans(BlogInfo blogInfo){
        if(blogInfo == null){
            return null;
        }
        BlogInfoResponse response = new BlogInfoResponse();
        BeanUtils.copyProperties(blogInfo,response);
        return response;
    }

    public static UserInfoResponse trans(UserInfo userInfo){
        if(userInfo == null){
            return null;
        }
        UserInfoResponse userInfoResponse = new UserInfoResponse();
        BeanUtils.copyProperties(userInfo, userInfoResponse);
        return userInfoResponse;
    }

    public static  BlogInfo trans(UpdateBlogRequest request){
        if(request == null){
            return null;
        }
        BlogInfo blogInfo = new BlogInfo();
        BeanUtils.copyProperties(request,blogInfo);
        return blogInfo;
    }
}
